(library (commands pwd)
  (export pwd
          cwd
          path-working-directory
          current-working-directory)
  (import (except (rnrs base) error map)
          (only (guile)
                lambda* λ
                ;; formatting
                simple-format
                ;; ports
                with-output-to-port
                current-output-port
                ;; other
                getcwd
                ;; controll flow
                unless
                )
          (alias)
          (shell-state))


  (define pwd
    (lambda* (#:key
              ;; command interface
              (previous-result '())
              (shell-state default-shell-state)
              (silent #f))
      "Return the current working directory. pwd does not make use of the
previous result, even if any is provided."
      (with-output-to-port (current-output-port)
        (λ ()
          (let ([cwd (getcwd)])
            ;; Write to output port.
            (unless silent
              (simple-format #t "~a\n" cwd))
            ;; Always return results and updated shell state.
            (values (list cwd)
                    shell-state))))))


  (alias cwd pwd)
  (alias path-working-directory pwd)
  (alias current-working-directory pwd))
